package com.monolithiot.cdn.management.service.impl;

import com.monolithiot.cdn.management.dao.BaseMapper;
import com.monolithiot.cdn.management.service.BaseService;

import java.util.List;

/**
 * 2018/11/18 Create by 郭文梁
 * BaseServiceImpl
 * 业务服务基类实现
 *
 * @author 郭文梁
 * @date 2018/11/18
 */
public abstract class BaseServiceImpl<T> implements BaseService<T> {
    /**
     * 对应实体类的Mapper
     *
     * @return Mapper
     */
    abstract BaseMapper<T> getMapper();

    @Override
    public List<T> list() {
        return getMapper().selectAll();
    }

    @Override
    public T save(T o) {
        int res = getMapper().insert(o);
        return res > 0 ? o : null;
    }

    @Override
    public T findById(Integer id) {
        return getMapper().selectByPrimaryKey(id);
    }

    @Override
    public T update(T obj) {
        int res = getMapper().updateByPrimaryKey(obj);
        return res > 0 ? obj : null;
    }
}
